<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Session;
use App\Api\Log\Models\ApiRequestLog;

class ApiAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $logData['request_start_time'] = microtime(true);
        //写入接口请求日志
        $apilog = new ApiRequestLog();
        $logData['apilog_id'] = $apilog->logApiRequest($request);
        Session::put('apiRequestData',arrayToObject($logData)); //记录执行开始时间
        //api授权区域

        return $next($request);
    }
}
